package top.wonew.helper.utils;

import org.json.JSONObject;

public class IResponse {
    public static <T> JSONObject success(T data) {
        return buildResponse(true, 200, "success", data);
    }

    public static <T> JSONObject success(T data, String message) {
        return buildResponse(true, 200, message, data);
    }

    public static <T> JSONObject success(T data, int code, String message) {
        return buildResponse(true, code, message, data);
    }

    public static <T> JSONObject fail(T data) {
        return buildResponse(false, -500, "failed.", data);
    }

    public static <T> JSONObject fail(T data, String message) {
        return buildResponse(false, -200, message, data);
    }

    public static <T> JSONObject fail(T data, int code, String message) {
        return buildResponse(false, code, message, data);
    }

    public static <T> JSONObject buildResponse(boolean status, int code, String message, T data) {
        JSONObject res = new JSONObject();
        res.put("status", status);
        res.put("code", code);
        res.put("message", message);
        res.put("timestamp", System.currentTimeMillis());
        res.put("data", data);
        return res;
    }
}
